package com.rules.admin.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.rules.admin.entity.GroovyShellModel;
import com.rules.admin.service.GroovyShellService;
import com.rules.admin.utils.ResultUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RequestMapping({"/groovyShell"})
@Controller
public class GroovyShellController {
   @Autowired
   private GroovyShellService groovyShellService;

   @RequestMapping(
      value = {"groovyShell_page"},
      method = {RequestMethod.GET}
   )
   @ResponseBody
   public IPage<GroovyShellModel> queryPage(GroovyShellModel groovyShellModel, IPage<GroovyShellModel> page) {
      return this.groovyShellService.queryPage(groovyShellModel, page);
   }

   @RequestMapping(
      method = {RequestMethod.POST}
   )
   @ResponseBody
   public Map<String, Object> addGroovyShell(@RequestBody GroovyShellModel groovyShellModel) {
      this.groovyShellService.save(groovyShellModel);
      return ResultUtils.getSuccessResultData();
   }

   @RequestMapping(
      value = {"/{id}"},
      method = {RequestMethod.GET}
   )
   @ResponseBody
   public Map<String, Object> getGroovyShell(@PathVariable("id") String id) {
      GroovyShellModel groovyShellModel = (GroovyShellModel)this.groovyShellService.getById(Long.parseLong(id));
      return ResultUtils.getSuccessResultData(groovyShellModel);
   }

   @RequestMapping(
      value = {"/{id}"},
      method = {RequestMethod.DELETE}
   )
   @ResponseBody
   public Map<String, Object> deleteGroovyShell(@PathVariable("id") String id) {
      this.groovyShellService.removeById(Long.parseLong(id));
      return ResultUtils.getSuccessResultData();
   }

   @RequestMapping(
      method = {RequestMethod.PUT}
   )
   @ResponseBody
   public Map<String, Object> updateGroovyShell(@RequestBody GroovyShellModel groovyShellModel) {
      this.groovyShellService.save(groovyShellModel);
      return ResultUtils.getSuccessResultData();
   }
}
